package com.lsa.tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ToArray2D {
	private static final String TYPE = "new int[][]{";
	
	public static void main(String[] args) throws IOException {
		InputStream in = ToArraysAsList.class.getResourceAsStream("ToArray2D.txt");
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

		String line = null;
		boolean isFirst = true;
		
		System.out.print(TYPE);
		
		while((line = br.readLine()) != null) {
			System.out.print(String.format("%s%s", (isFirst? "" : ','), toArray(line)));
			isFirst = false;
		}
		System.out.println("}");
	}

	private static String toArray(String line) {
		String[] parts = line.split("\\s+");
		StringBuilder sb = new StringBuilder();
		sb.append('{');
		boolean isFirst = true;
		for (int i = 0; i < parts.length; i++) {
			String p = parts[i];
			if (p.trim().isEmpty()) continue;
			if (!isFirst) {
				sb.append(',');
			}
			sb.append(p);
			
			isFirst = false;
		}
		sb.append('}');
		return sb.toString();
	}
}
